#include "shader/skyBoxShader.h"

bool SkyBoxShader::is_built = false;
GLuint SkyBoxShader::ID;

SkyBoxShader::SkyBoxShader() {
	if (!is_built) {
		ID = load_shader("../shader/textureShader.vert", "../shader/textureShader.frag");
		is_built = true;
	}
	//initialize light param
}

void SkyBoxShader::render(Mesh& mesh, glm::mat4& viewMat, glm::mat4& projMat) const {
	glDepthFunc(GL_LEQUAL);
	glUseProgram(ID);
	
	//glUniformMatrix4fv(glGetUniformLocation(ID, "model"), 1, GL_FALSE, glm::value_ptr(modelMat));
	glm::mat4 view = glm::mat4(glm::mat3(viewMat));
	glUniformMatrix4fv(glGetUniformLocation(ID, "view"), 1, GL_FALSE, glm::value_ptr(view));
	glUniformMatrix4fv(glGetUniformLocation(ID, "proj"), 1, GL_FALSE, glm::value_ptr(projMat));

	//增加纹理
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, textureID);
	GLuint tex_loc;
	tex_loc = glGetUniformLocation(ID, "skybox");
	glUniform1i(tex_loc, 0);

	glBindVertexArray(mesh.get_VAO());
	glDrawElements(GL_TRIANGLES, mesh.indices.size(), GL_UNSIGNED_INT, 0);
	glDepthFunc(GL_LESS);
}